var SERVER_URL;
if (top.location.href.indexOf("http://9leap.net") != -1) {
	SERVER_URL = "http://match-enchant.appspot.com";
} else {
	SERVER_URL = "http://localhost:8888";
}
var MESSAGES = [];

enchant();

$(function() {
	var game = new Game(160, 160);
	game.fps = 32;
	game.twitterRequest("account/verify_credentials");
	game.onload = function() {
		var twId = game.twitterAssets["account/verify_credentials"][0].screen_name;

		var timer = new Node();
		timer.addEventListener(Event.ENTER_FRAME, function(event) {
			if (game.frame % 50 == 0) poll(twId);
		});

		game.rootScene.addChild(timer);
	};
	game.start();
});

function poll(screenName) {
	$.ajax({
		url : SERVER_URL + "/getMessage",
		dataType : "jsonp",
		data : {
			toName : screenName
		},
		success : function(data) {
			console.log(data);
		}
	});
}
